package com.lovo.test;

import java.text.Format;
import java.util.Arrays;
import java.util.Locale;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Test2 t = new Test2();
//        t.camelToSnake();
//        t.snakeToCamel();
        t.currency();
    }
    // 驼峰转蛇形
    public void camelToSnake(){
        Scanner sc = new Scanner(System.in);
        String result = "";
        System.out.println("请输入驼峰字符串：");
        String str = sc.next();
        for (int i = 0; i < str.length(); i++) {
            char a = str.charAt(i);
            if (a >= 'A' && a <= 'Z' && i != 0) {
                result += "_" + a;
            } else {
                result += a + "";
            }
        }
        System.out.println(result.toLowerCase());
    }

    // 蛇形转驼峰
    public void snakeToCamel(){
        Scanner sc = new Scanner(System.in);
        String result = "";
        System.out.println("请输入蛇形字符串：");
        String str = sc.next();
        String[] str1 = str.split("_");
        for (int i = 0; i < str1.length; i++){
            if (i != 0){
                char[] a = str1[i].toCharArray();
                a[0] -= 32;
                str1[i] = new String(a); //将字符重新转换为字符串
            }
            result += str1[i];
        }
        System.out.println(result);
    }

    // 货币数字以千分位的方式表示
    public void currency(){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入double数：");
        Double a = sc.nextDouble();
        String str = String.valueOf(a);
        String[] str1 = str.split("\\.");
        String[] str2 = str1[0].split("");
        String str3 = "";
        int b = 0;
        for (int i = str2.length-1;i>=0;i--){
            b++;
            str3 = str2[i]+str3;
            if (b==3){
                str3 = ","+str3;
                b=0;
            }
        }
        str3+="."+str1[1];
        System.out.println(str3);
    }
}
